package cn.legend.travel.destination.main.dao.persist.repository.impl;


import cn.legend.travel.common.pojo.po.SceneryPO;
import cn.legend.travel.destination.main.dao.persist.mapper.SceneryMapper;
import cn.legend.travel.destination.main.dao.persist.repository.ISceneryRepository;
import cn.legend.travel.destination.main.pojo.vo.RegionVO;
import cn.legend.travel.destination.main.pojo.vo.SceneryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;


@Slf4j
@Repository
public class SceneryRepositoryImpl implements ISceneryRepository {
    @Autowired
    private SceneryMapper sceneryMapper;

    @Override
    public List<SceneryPO> selectByDestinationId(Long destinationId) {
        return sceneryMapper.selectByBestinationId(destinationId);
    }

    @Override
    public List<SceneryPO> selectByBestinationIds(Long destinationId, Pageable pageable) {
        int pageSize = pageable.getPageSize();
        int pageNumber = pageable.getPageNumber()*pageSize;
        System.err.println("pageNumber:"+pageNumber+";pageSize:"+pageSize);
        return sceneryMapper.selectByBestinationIds(destinationId,pageSize,pageNumber);
    }

    @Override
    public List<RegionVO> selectById(Long destinationId) {
        return sceneryMapper.selectById(destinationId);
    }

    @Override
    public List<SceneryVO> selectAll() {
        return sceneryMapper.selectAll();
    }


    @Override
    public int selectCountDistrict(Long id) {
        return sceneryMapper.selectCountDistrict(id);
    }

    @Override
    public int selectCountHotel(Long id) {
        List<RegionVO> regionVOS = sceneryMapper.selectFormRegionVO(id);
        int countHotels = 0;
        for (RegionVO regionVO : regionVOS) {
            int countHotel = sceneryMapper.selectCountHotel(regionVO.getId());
            countHotels+=countHotel;
        }
        return countHotels;
    }

    @Override
    public int selectCountDelicacy(Long id) {
        return sceneryMapper.selectCountDelicacy(id);
    }
}
